import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseInterceptors, UploadedFiles } from '@nestjs/common';
import { PersonService } from './person.service';
import { CreatePersonDto } from './dto/create-person.dto';
import { UpdatePersonDto } from './dto/update-person.dto';
import { AnyFilesInterceptor } from '@nestjs/platform-express';

@Controller('api/person')
export class PersonController {
  constructor(private readonly personService: PersonService) {}

  // 路由是从上往下匹配的
  @Get('find')
  query(@Query('name') name: string, @Query('age') age: number) {
    return {
      name, age
    };
  }

  @Get(':id')
  urlParam(@Param('id') id: string) {
    return {
      id
    };
  }

  @Post()
  body(@Body() createPersonDto: CreatePersonDto) {
    return {
      createPersonDto
    }
  }

  @Post('file')
  @UseInterceptors(AnyFilesInterceptor({
      dest: 'uploads/'
  }))
  body2(@Body() createPersonDto: CreatePersonDto, @UploadedFiles() files: Array<Express.Multer.File>) {
    return {
      files,
      createPersonDto
    }
  }
}
